package cn.com.bluemoon.daps.webhook.design;

import cn.com.bluemoon.daps.common.enums.StandardAuditStatus;
import cn.com.bluemoon.daps.common.toolkit.BmAssetUtils;

import java.util.ServiceLoader;
import java.util.concurrent.ConcurrentHashMap;


/**
 * @author Jarod.Kong
 * @date 2021/1/11 17:27
 */
public class StrategyClient {
    private static final ConcurrentHashMap<StandardAuditStatus, AuditStatusChange>
            AUDIT_STATUS_MAP = new ConcurrentHashMap<>();

    static {
        ServiceLoader<AuditStatusChange> load = ServiceLoader.load(AuditStatusChange.class);
        for (AuditStatusChange change : load) {
            BmAssetUtils.notNull(change.auditStatus(), "实现类必须指定对应状态");
            AUDIT_STATUS_MAP.put(change.auditStatus(), change);
        }
    }

    public String audit(String auditId,
                        StandardAuditStatus targetAuditStatus,
                        Integer modifyTypeDefine,
                        String nextStandardId) {
        AuditStatusChange statusChange = AUDIT_STATUS_MAP.get(targetAuditStatus);
        if (statusChange != null) {
            String change = statusChange.change(auditId, targetAuditStatus, modifyTypeDefine, nextStandardId);
            return change;
        }
        return null;
    }

}
